package com.eco.mam.work.request;

import java.io.BufferedReader;

import org.apache.log4j.Logger;

import com.eco.mam.work.ConfigParameters;
import com.eco.mam.work.DataException;
import com.eco.mam.work.request.resource.WorkRequestConfig;
import com.eco.mam.work.request.transform.XMLTransformer;

public class WorkRequestProcessor implements MamWorkProcessor {
	static final Logger logger = Logger.getLogger(WorkRequestProcessor.class);

	public ResponseMap process(RequestMap requestMap) {
		// TODO Auto-generated method stub

		logger.info("Entering mehthod WorkRequestProcessor.process() ");
		/* loading the csv file as a stream by passing the csv file name */
		BufferedReader reader;
		try {
			reader = WorkRequestProcessHelper
					.getWorkRequestAsCsv(WorkRequestConfig
							.getFileName(ConfigParameters.CSV_INPUT_FILE));
		
			if (logger.isDebugEnabled()) {
				logger.debug("buffer reader  :" + reader);
			}
			/*
			 * Calling the xmltransformer to do the transformation from csv to xml
			 * transformation
			 */
			ResponseMap responseMap = new XMLTransformer()
					.transform(new RequestMap("csvDataStream", reader));

			if (logger.isDebugEnabled()) {
				logger.debug("ResponseMap   :" + responseMap);
			}


		} catch (DataException e) {
			if(logger.isDebugEnabled()){
				
				logger.debug(e);
				
			}
		}

		
				
		return null;

	}

}
